from django.shortcuts import render, redirect
from .forms import PersonInfoForm, VocationForm
from .models import PersonInfo

# Create your views here.

def person_info_view(request):
    if request.method == 'POST':
        form = PersonInfoForm(request.POST)
        if form.is_valid():
            form.save()  # 保存 PersonInfo
            return redirect('success')  # 重定向到成功页面
    else:
        form = PersonInfoForm()
    
    return render(request, 'db/person_info_form.html', {'form': form})

def vocation_view(request):
    if request.method == 'POST':
        form = VocationForm(request.POST)
        if form.is_valid():
            form.save()  # 保存 Vocation
            return redirect('success')  # 重定向到成功页面
    else:
        form = VocationForm()
    
    return render(request, 'db/vocation_form.html', {'form': form})

def success_view(request):
    return render(request, 'db/success.html')  # 渲染成功页面模板

def db_home_view(request):
    return render(request, 'db/db_home.html')  # 渲染 DB 应用主页模板
